package com.neu.service.impl;

import com.neu.domain.Product;
import com.neu.dto.ProductDTO;
import com.neu.mapper.ProductMapper;
import com.neu.service.ProductService;
import com.neu.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;

    @Override
    public List<ProductVO> selectByShopId(Integer shopId) {
        return productMapper.selectByShopId(shopId);
    }

    @Override
    public List<ProductVO> find(ProductDTO productDTO) {
        return productMapper.find(productDTO);
    }

    @Override
    public int add(ProductDTO productDTO) {

        Product product = new Product();
        product.setName(productDTO.getName());
        product.setDescription(productDTO.getDescription());
        product.setPhoto(productDTO.getPhoto());
        product.setPrice(productDTO.getPrice());
        product.setShop_id(productDTO.getShopId());

        int count = productMapper.add(product);

        return count;
    }

    @Override
    public int delete(ProductDTO productDTO) {
        int count = productMapper.delete(productDTO);
        return count;
    }
}
